package business.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import model.TError;
import business.basic.iHibBaseDAO;
import business.basic.iHibBaseDAOImpl;
import business.dao.ErrorDAO;

@Component("errordao")
public class ErrorDAOImpl implements ErrorDAO {
	
	private iHibBaseDAO bdao =null;
	
	public ErrorDAOImpl() {
		bdao = new iHibBaseDAOImpl();
	}

	public void setBdao(iHibBaseDAO bdao) {
		this.bdao = bdao;
	}

	@Override
	public int add(TError error) {
		Object obj = bdao.insert(error);
		if (obj!=null) {
			return Integer.parseInt(obj.toString());
		}
		return 0;
	}

	@Override
	public boolean update(TError error) {
		return bdao.update(error);
	}

	@Override
	public boolean delete(int errorid) {
		return bdao.delete(TError.class, errorid);
	}

	@Override
	public TError getTErrorId(int errorid) {
		return (TError)bdao.findById(TError.class, errorid);
	}

	@Override
	public List<TError> getTError() {
		String hql = "from TError";
		return bdao.select(hql);
	}

	@Override
	public List<TError> getTErrorByWhere(String wherecondition, int startPage,
			int pageSize) {
		String hql = "from TError";
		if (wherecondition !=null && !wherecondition.equals("")) {
			hql += wherecondition;
		}
		return bdao.selectByPage(hql, startPage, pageSize);
	}

	@Override
	public int getAmounTErrorByWhere(String wherecondition) {
		String hql = "select count(*) from TError";
		if (wherecondition !=null && !wherecondition.equals("")) {
			hql += wherecondition;
		}
		return bdao.selectValue(hql);
	}

}
